package com.tulele.vtool.task.process.articlePush;

import com.tulele.vtool.bus.mapper.log.PushDetailLogMapper;
import com.tulele.vtool.bus.mapper.log.PushHeadLogMapper;
import com.tulele.vtool.bus.model.UserInfo;
import com.tulele.vtool.bus.model.log.PushHeadLog;
import com.tulele.vtool.bus.service.IUserService;
import com.tulele.vtool.task.async.ThirdTimeArticlePushAsyncTask;
import com.tulele.vtool.task.async.UploadTempMsgPushAsyncTask;
import com.tulele.vtool.util.DateUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
public class BFArticleInfoPushTask extends QuartzJobBean {

    @Autowired
    private ThirdTimeArticlePushAsyncTask thirdTimeArticlePushAsyncTask;

    @Autowired
    private UploadTempMsgPushAsyncTask uploadTempMsgPushAsyncTask;

    @Autowired
    private IUserService userService;

    @Value("${sleepTime}")
    private String sleepTimeSet;

    @Value("${spring.application.name}")
    private String springProfilesActive;

    @Autowired
    private PushHeadLogMapper pushHeadLogMapper;

    @Autowired
    private PushDetailLogMapper pushDetailLogMapper;

    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        String profile = "prodhkbw";

        if ("2022-02-15".equals(DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate()))) {  //防止到了第二天 还要发

            List<UserInfo> userList = userService.getUserListByGzhCode(profile);
            for (UserInfo userInfo : userList) {
                try {
                    //补发时再启动
                    thirdTimeArticlePushAsyncTask.executeBF("wxPushUser" + userInfo.getUserId(), 0, userInfo, profile);
                } catch (Exception e) {

                }
            }
        }
    }
}
